﻿using NewBee.Core.Data;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace NewBee.Core.DataService
{

    public class Survey_ShareDS : BaseDataService
    {
        /// <summary>
        /// 
        /// </summary>
        public override DbHelper _DbHelper  //数据库操作类
        {
            get
            {
                return new DbHelper(DataConnection.ConnectionString, DataConnection.QueryConnectionString,
                    DataConnection.DriverType);
            }
        }
        public override string TableName    //重写表名
        {
            get
            {
                return "Survey_Share";
            }
        }
        /// <summary>
        /// 获取实体根据ID
        /// </summary>
        public Models.Survey_Share GetByID(string id)
        {
            string sql = "Select * From Survey_Share Where ID = @Id";
            return this.GetBaseBySql<Models.Survey_Share>(sql, new { Id = id });
        }

        public Models.Survey_Share GetByUserId(string userId)
        {
            string sql = "Select * From Survey_Share Where UserId = @UserId";
            return this.GetBaseBySql<Models.Survey_Share>(sql, new { UserId = userId });
        }

        /// <summary>
        /// 插入
        /// </summary>
        public bool Insert(Models.Survey_Share Survey_Share)
        {
            int _int = this.Insert<Models.Survey_Share>(Survey_Share);
            if (_int <= 0)
                return false;
            else
                return true;
        }

        /// <summary>
        /// 修改
        /// </summary>
        public bool Update(Models.Survey_Share Survey_Share)
        {
            int _int = _DbHelper.Update<Models.Survey_Share>(Survey_Share)
                .PrimaryKeys("ID")
                .Where("ID=@0")
                .Parameters(Survey_Share.ID)
                .Execute();

            if (_int <= 0)
                return false;
            else
                return true;
        }

        /// <summary>
        /// 修改ResultNum
        /// </summary>
        public bool Update(Guid id, int num)
        {
            int _int = _DbHelper.Update("Survey_Share")
                .Column("ResultNum", num)
                .Where("ID=@0")
                .Parameters(id)
                .Execute();

            if (_int <= 0)
                return false;
            else
                return true;
        }

        /// <summary>
        /// 删除
        /// </summary>
        public bool Delete(string id)
        {
            string sql = "Delete From Survey_Share Where ID in (@Id)";
            int _int = this.BaseExecuteBySql(sql, new { Id = id });
            if (_int <= 0)
                return false;
            else
                return true;
        }

        /// <summary>
        /// 标记删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool Remove(string id)
        {
            int _int = _DbHelper.Update("Survey_Share")
            .Column("Status", -1)
            .Where("ID in (@0)")
            .Parameters(id)
            .Execute();
            if (_int <= 0)
                return false;
            else
                return true;
        }

    }
}